//
//  MyProjectDetailTableViewCell.m
//  WideHelp
//
//  Created by ENERGY on 2018/8/12.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "MemberStoryTableViewCell.h"
#define imgW 8/WIDTH_6_SCALE
@interface MemberStoryTableViewCell()
@property (nonatomic, strong)UIImageView * circleImg;
@property (nonatomic, strong)UILabel * contentLab;
@end

@implementation MemberStoryTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.circleImg];
        [self.contentView addSubview:self.contentLab];
        [self.contentView addSubview:self.topVerticalDashLine];
        [self.contentView addSubview:self.bottomVerticalDashLine];
        
    }return self;
}
+ (CGFloat)heightForCellWithComment:(NSDictionary *) model{
    return [self contentLabelHeight:model[@"content"]] + 24/WIDTH_6_SCALE;
}

+ (CGFloat)contentLabelHeight:(NSString *) text{
    CGRect rectToFit = [text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 16/WIDTH_6_SCALE * 2 - 11/WIDTH_6_SCALE - imgW, MAXFLOAT)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.0f]}
                                          context:nil];
    return rectToFit.size.height;
}
- (UILabel *)contentLab{
    if (!_contentLab) {
        _contentLab = [[UILabel alloc] init];
        _contentLab.font = DEF_FontSize_14;
        _contentLab.textColor = [UIColor blackColor];
        _contentLab.textAlignment = NSTextAlignmentLeft;
        _contentLab.backgroundColor = [UIColor whiteColor];
        _contentLab.lineBreakMode = 0;
        _contentLab.numberOfLines = 0;
    }return _contentLab;
}
- (UIImageView *)circleImg{
    if (!_circleImg) {
        _circleImg = [[UIImageView alloc] init];
        _circleImg.backgroundColor = getColor(greenBGColor);
        _circleImg.layer.cornerRadius = imgW/2;
        _circleImg.layer.masksToBounds = YES;
    }return _circleImg;
}
- (DashesLineView *)topVerticalDashLine{
    if (!_topVerticalDashLine) {
        _topVerticalDashLine = [[DashesLineView alloc] initWithLineLength:4 withLineSpacing:3 withLineColor:getColor(greenBGColor)];
    }return _topVerticalDashLine;
}
- (DashesLineView *)bottomVerticalDashLine{
    if (!_bottomVerticalDashLine) {
        _bottomVerticalDashLine = [[DashesLineView alloc] initWithLineLength:4 withLineSpacing:3 withLineColor:getColor(greenBGColor)];
    }return _bottomVerticalDashLine;
}
- (void)setModel:(NSDictionary *)model{
    _model = model;
    self.contentLab.text = model[@"content"];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.circleImg.frame = CGRectMake(16/WIDTH_6_SCALE, 0, imgW, imgW);
    self.circleImg.centerY = self.contentView.centerY;
    self.contentLab.frame = CGRectMake(self.circleImg.right + 11/WIDTH_6_SCALE, 12/WIDTH_6_SCALE, SCREEN_WIDTH - 16/WIDTH_6_SCALE * 2 - 11/WIDTH_6_SCALE - imgW, [[self class] contentLabelHeight:self.model[@"content"]]);
    self.topVerticalDashLine.frame = CGRectMake(0, 0, 0.5, self.contentView.height/2);
    self.topVerticalDashLine.centerX = self.circleImg.centerX;
    self.bottomVerticalDashLine.frame = CGRectMake(0, self.contentView.height/2, 0.5, self.contentView.height/2);
    self.bottomVerticalDashLine.centerX = self.circleImg.centerX;
}
@end
